//
//  TeBieZhuYiOnShiLiBaoGaoTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/5/5.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "TeBieZhuYiOnShiLiBaoGaoTableViewCell.h"

@implementation TeBieZhuYiOnShiLiBaoGaoTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 布局
- (void)addMySubview
{
    // 底部灰色条
    self.grayLineOnBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 214 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
    self.grayLineOnBottom.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.07];
    [self.contentView addSubview:_grayLineOnBottom];
}

- (void)setTeBieZhuYiArray:(NSMutableArray *)teBieZhuYiArray
{
    // 进行标签的动态布局
    // 记录左边开始位置
    CGFloat leftPoint = 0.0;
    // 记录其实的高度
    CGFloat heightPoint = 0.0;
    // 记录换了几次行
    NSInteger huanHangCount = 0;
    for (int i = 0; i < teBieZhuYiArray.count; i++) {
        CGFloat tempWidth = [[NetStatusHandle shareHandle] adjustWidth:teBieZhuYiArray[i] size:16 height:30];
        if ((leftPoint + tempWidth) > 329 * kAdjustParamater) {
            // 说明需要换行,这时需要重置左起位置
            leftPoint = 0.0;
            huanHangCount++;
          //  NSLog(@"huanHangCount = %ld", huanHangCount);
            heightPoint = (30 + 22) * kAdjustParamater * huanHangCount;
        }
      //  NSLog(@"heightPoint = %f", heightPoint);
        UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(23 * kAdjustParamater + leftPoint, 40 * kAdjustParamater + heightPoint, 50 * kAdjustParamater, 30 * kAdjustParamater)];
        tempLabel.text = teBieZhuYiArray[i];
        tempLabel.backgroundColor = [UIColor whiteColor];
        tempLabel.textColor = [UIColor colorWithRed:82 / 255.0 green:199 / 255.0 blue:220 / 255.0 alpha:1];
        tempLabel.tag = 200 + i;
        tempLabel.textAlignment = NSTextAlignmentCenter;
        tempLabel.font = [UIFont systemFontOfSize:k16Big];
        tempLabel.layer.cornerRadius = 10 * kAdjustParamater;
        tempLabel.layer.masksToBounds = YES;
        tempLabel.layer.borderColor = [[UIColor colorWithRed:72 / 255.0 green:170 / 255.0 blue:204 / 255.0 alpha:1] CGColor];
        tempLabel.layer.borderWidth = 1 * kAdjustParamater;
       
        
        // 进行自适应宽度
        CGRect newFrame = tempLabel.frame;
        newFrame.size.width = [[NetStatusHandle shareHandle] adjustWidth:tempLabel.text size:16 height:30] + 16 * kAdjustParamater;
        tempLabel.frame = newFrame;
       
        // 保存下一个label的左起位置
        leftPoint = tempLabel.frame.size.width + 13 * kAdjustParamater + leftPoint;
    //    NSLog(@"左起为止:%f", leftPoint);
        [self.contentView addSubview:tempLabel];
    }
    
    // 取出最后一个label
    UILabel *lastLabel = (UILabel *)[self.contentView viewWithTag:199 + teBieZhuYiArray.count];
    
    self.grayLineOnBottom.bottom = lastLabel.bottom + 40 * kAdjustParamater;
    
    
    
    
    
    
}

@end
